<?php


namespace api\crm\validate;


use api\crm\model\UserModel;
use think\Validate;

class CustomerValidate extends Validate
{
    protected $rule = [
        'user_login' => 'require|checkUserLogin|mobile',
        'company_id' => 'require',
    ];

    protected $message = [
        'user_login.require' => '手机号码不能为空',
        'user_login.checkUserLogin' => '该手机号码已被使用',
        'user_login.mobile' => '请输入有效的手机号码',
        'company_id.require' => '返卡账号不能为空',
    ];

    protected function checkUserLogin($value, $rule, $data = [])
    {
        $user = UserModel::where(['user_login' => $data['user_login'], 'company_id' => $data['company_id']])->find();
        return $user ? false : true;
    }
}